{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b6355925",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2676dad8",
   "metadata": {},
   "source": [
    "**Import Data**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0a362bcd",
   "metadata": {},
   "outputs": [],
   "source": [
    "Private_Sunk_Data=pd.read_csv(\"Private_Sunk_Data.csv\")\n",
    "Public_Sunk_Data=pd.read_csv(\"Public_Sunk_Data.csv\")\n",
    "\n",
    "Private_Risk_Data=pd.read_csv(\"Private_Risk_Data.csv\")\n",
    "Public_Risk_Data=pd.read_csv(\"Public_Risk_Data.csv\")\n",
    "\n",
    "Private_Loss_Data=pd.read_csv(\"Private_Loss_Data.csv\")\n",
    "Public_Loss_Data=pd.read_csv(\"Public_Loss_Data.csv\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3798264b",
   "metadata": {},
   "source": [
    "**Merge Data**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9231f083",
   "metadata": {},
   "outputs": [],
   "source": [
    "data=pd.concat([Private_Sunk_Data,Public_Sunk_Data,Private_Risk_Data,Public_Risk_Data,Private_Loss_Data,Public_Loss_Data])\n",
    "data=data.reset_index(drop=True)\n",
    "data=data.drop(\"Unnamed: 0\",axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ebbb7b39",
   "metadata": {},
   "outputs": [],
   "source": [
    "data=data[abs(data[\"Coefficient Value\"])<.91]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe4ff0d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "for treatment in data.Treatment.unique():\n",
    "    for factor in data.Factor.unique():\n",
    "        for coeff in data[(data.Treatment==treatment)&(data.Factor==factor)][\"Coefficient Value\"].unique():\n",
    "            for num,index in enumerate(data[(data.Treatment==treatment)&(data.Factor==factor)&(data[\"Coefficient Value\"]==coeff)].index.values):\n",
    "                data.loc[data.index==index,\"Simulation Number\"]=num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "74ebf477",
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"Factor\"]=data.apply(lambda row: \"Sunk Cost\" if row[\"Factor\"]==\"Sunk Cost Coefficient\" else row[\"Factor\"], axis=1)\n",
    "data[\"Factor\"]=data.apply(lambda row: \"Loss Aversion\" if row[\"Factor\"]==\"Loss Aversion Coefficient\" else row[\"Factor\"], axis=1)\n",
    "data[\"Factor\"]=data.apply(lambda row: \"CRRA\" if row[\"Factor\"]==\"CRRA Coefficient\" else row[\"Factor\"], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20f306e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "data[\"Coefficient Value\"]=data.apply(lambda row: abs(row[\"Coefficient Value\"]),axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fd50e12",
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv(\"Behavioral_Factors.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f049bb56",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
